package cn.fws.meap.user.web;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.fws.meap.user.entity.Account;
import cn.fws.meap.user.service.IAccountService;
import cn.fws.framework.web.contoller.BaseController;
import cn.fws.framework.web.page.PagingResult;
import cn.fws.framework.web.contoller.JsonResponse;

/**
 * 账户 信息操作处理
 * 
 * @author chenkh
 * @date 2019-03-07
 */
@RestController
@RequestMapping("/meap/account")
@Api(tags = "账户 信息操作处理")
public class AccountController extends BaseController{

	@Autowired
	private IAccountService accountService;


	//查询当前账户余额
	@ApiOperation(value = "查询账户列表")
	@PostMapping("/getAccountMoney")
	public JsonResponse getAccountMoney(String openId){
		Account account = accountService.selectById(openId);
		return JsonResponse.success("操作成功",account.getAccBalance());
	}
	
	/**
	 * 查询账户列表
	 */
	//@RequiresPermissions("meap:account:list")
	@ApiOperation(value = "查询账户列表")
	@PostMapping("/list")
	public PagingResult<Account> list(Account account){
		startPage();
        List<Account> list = accountService.selectList(account);
		return getPagingResult(list);
	}
	
	/**
	 * 新增保存账户
	 */
	//@RequiresPermissions("meap:account:add")
	@ApiOperation("新增保存账户")
	@ApiImplicitParam(name = "account", value = "新增保存账户",dataType = "Account")
	@PostMapping("/add")
	public JsonResponse addSave(Account account)	{		
		return toAjax(accountService.insert(account));
	}

	/**
	 * 修改保存账户
	 */
	//@RequiresPermissions("meap:account:edit")
	@ApiOperation("修改保存账户")
	@ApiImplicitParam(name = "account", value = "修改保存账户",dataType = "Account")
	@PutMapping("/edit")
	public JsonResponse editSave(Account account)	{		
		return toAjax(accountService.update(account));
	}
	
	/**
	 * 删除账户
	 */
	//@RequiresPermissions("meap:account:remove")
	@ApiOperation("修改保存账户")
	@ApiImplicitParam(name = "ids", value = "根据id删除账户",dataType = "String")
	@DeleteMapping( "/remove")
	public JsonResponse remove(String ids)	{		
		return toAjax(accountService.deleteByIds(ids));
	}
}
